mv — Move & Rename Files/Directories Linux coreutils
mv (move) is the “relocation” command on Linux. It can rename a file (same folder, new name) or move it into a new directory.
On a VPS, mv is used constantly for deployments (swap new builds), backups (archive old configs), log rotations, and even WordPress operations like disabling plugins by renaming their folders.
If cp is “make a copy,” mv is “change where it lives.”
Renaming is just moving within the same directory.
If the destination already exists, mv can overwrite it. Use -i or -n when safety matters.
Prerequisites
- Linux VPS (Ubuntu recommended)
- SSH access
- Familiarity with WordPress paths like
/var/www/html/,/backups/
Verify mv exists (GNU coreutils)
command -v mv
Expected output (example):
/usr/bin/mv
Check version:
mv --version
Expected output (example):
mv (GNU coreutils) 9.4
Verify cp exists (used in examples)
command -v cp
cp --version
Syntax (complete)
mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...
Notes:
- If
DESTis an existing directory, sources are moved intoDEST/. - If
DESTis not a directory,SOURCEis renamed/moved to theDESTpath. - If the destination path already exists,
mvmay overwrite it unless you use a safety flag.
Options That Matter
| Option | Meaning | Typical Use |
|---|---|---|
-i | Interactive: prompt before overwrite | Protect configs like wp-config.php |
-n | No overwrite (no-clobber) | Safe automation, preserve backups |
-f | Force overwrite (no prompt) | CI/CD deployments (use carefully) |
-u | Move only if source is newer | Refresh updated theme assets |
-v | Verbose: show each action | Logs/debugging |
-t DIR | Move sources into DIR | Scripts; avoids DEST ambiguity |
-T | Treat DEST as a normal file | Avoid moving into an existing dir |
-b, --backup[=CONTROL] | Backup overwritten destination | Safer overwrites with rollback |
-- | End of options | Move names starting with - |
--help | Show help | Quick reference |
--version | Show version | Compatibility checks |
- Manual work: prefer
-i - Automation: prefer
-n(or controlled-fwith logging) - Unsure what
DESTis: add-vand confirm withls -ld DEST
Common Patterns
- Rename (same folder)
- Move into directory
- Safe move (no overwrite)
- Overwrite w/ backup
- Many sources (-t)
- Verbose logs
mv index.php index-old.php
mv wp-config.php /backups/
mv -n wp-config.php /backups/
mv -bv new-config.php wp-config.php
mv -v -t /backups -- wp-config.php debug.log
mv -v style.css /var/www/html/wp-content/themes/mytheme/
Best Practices
- For manual work on important files, prefer
mv -iv ...(prompt + visibility). - For scripts, prefer
mv -n ...when you must never overwrite. - Confirm what
DESTis before moving:ls -ld DEST - If overwriting is expected, keep a rollback copy:
mv -bv new-config.php wp-config.php - When moving many sources, prefer
-tand--:mv -t /backups -- file1 file2 - Need a copy instead of a move? Use
cp(examples use it for backups).
Renaming a plugin folder usually disables it because WordPress can’t find its entry point.
Troubleshooting
| Problem | Likely Cause | Fix |
|---|---|---|
| File not moved | Wrong path | Check with ls and use absolute paths |
Permission denied | Owned by root / restricted path | Use sudo mv ... or fix ownership |
| File overwritten | No safety flag used | Use -i (prompt) or -n (skip) |
| Unexpected rename vs move | Destination wasn’t a directory | Confirm with ls -ld DEST |
Quick verification commands (HTML)
# Confirm current directory
pwd
# Confirm what DEST is
ls -ld DEST
# Check result
ls -lah /path/to/target
Cheat Sheet
mv SOURCE DEST # Rename/move one path
mv SRC1 SRC2 DIR/ # Move many sources into DIR/
mv -t DIR SRC1 SRC2 # Same, safer for scripting
mv -iv SOURCE DEST # Prompt + verbose (good manual default)
mv -n SOURCE DEST # Never overwrite
mv -bv new-config.php wp-config.php # Overwrite but keep wp-config.php~
mv -- -file ./dest/ # Move a name starting with '-'
mv -T SOURCE DEST # Treat DEST as a normal file
Mini Quiz
- What does
mv -ido when a file already exists at the destination? - Which flag prevents overwriting existing files?
- How would you disable a plugin without logging into WP admin using
mv? - Which option shows each file being moved?
- Prompts before overwriting.
-n- Rename the plugin folder (e.g.,
old-plugin->old-plugin-disabled). -v
Worked Examples (with expected output)
Examples come after the concepts so the flags make sense when you see them in action.
Rename a file
mv index.php index-old.php
Expected output: (silent success)
Move a file to another directory
mv wp-config.php /backups/
Expected output: (silent success)
Move and rename at the same time
mv debug.log /backups/debug-2025.log
Expected output: (silent success)
Move multiple files into a directory
mv file1.php file2.php /var/www/html/wp-content/
Expected output: (silent success)
Verbose mode
mv -v style.css /var/www/html/wp-content/themes/mytheme/
Expected output:
renamed 'style.css' -> '/var/www/html/wp-content/themes/mytheme/style.css'
Interactive overwrite
mv -i wp-config.php /backups/
Expected output (if file exists at destination):
mv: overwrite '/backups/wp-config.php'?
Force overwrite (automation-style)
mv -f new-config.php wp-config.php
Expected output: (silent success)
This can replace critical configs without warning.
No overwrite
mv -n wp-config.php /backups/
Expected output: (silent success; skips if destination exists)
Move only if newer (-u)
mv -u new-style.css /var/www/html/wp-content/themes/mytheme/
Expected output: (silent success if source is newer)
Move a directory
mv wp-content/uploads/2024 wp-content/old_uploads/
Expected output: (silent success)
Rename a directory (disable a plugin)
mv wp-content/plugins/old-plugin wp-content/plugins/old-plugin-disabled
Expected output: (silent success)
Move with wildcard
mv *.log /var/log/wp/
Expected output: (silent success)
ls *.log
Move into /tmp/
mv test.php /tmp/
Expected output: (silent success)
Move multiple directories with brace expansion
mv {themes,plugins} /backups/wp-content/
Expected output: (silent success)
Keep a copy (workaround)
cp index.php index-copy.php && mv index.php archive/
Expected output: (silent success)
Rename logs by date
mv debug.log debug-$(date +%Y-%m-%d).log
Expected output: (silent success)
Move with sudo
sudo mv wp-config.php /etc/wordpress/
Expected output: (silent success)
Replace existing file with verbose + force
mv -vf new-index.php index.php
Expected output:
renamed 'new-index.php' -> 'index.php'
Move folder contents (keep the folder)
mv wp-content/cache/* wp-content/old_cache/
Expected output: (silent success)
Bulk move using find
find . -name "*.bak" -exec mv -v {} backups/ \;
Expected output (example):
renamed './wp-config.php.bak' -> 'backups/wp-config.php.bak'
Move an entire WordPress site directory (advanced)
mv -v /var/www/html /var/www/old_html
Expected output:
renamed '/var/www/html' -> '/var/www/old_html'
Moving the web root can break your live site unless your web server config is updated.